package com.dzsw.thread;

public class TwoWaitThreadSample {

    public static void main(String[] args) {
        Object obj = new Object();
        // t1
        new Thread(() -> {
            synchronized (obj) {
                try {
                    Thread.sleep(3 * 1000);
                    System.out.println("t1 start waiting. == " + Thread.currentThread().getName());
                    obj.wait();
                    System.out.println("t1 end.");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        // t2
        new Thread(() -> {
            synchronized (obj) {
                try {
                    System.out.println("t2 start waiting. == " + Thread.currentThread().getName());
                    obj.wait();
                    System.out.println("t2 end.");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
//        try {
//            Thread.sleep(3 * 1000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        // t3
        new Thread(() -> {
            synchronized (obj) {
                try {
                    System.out.println("t3 start waiting. == " + Thread.currentThread().getName());
                    obj.notify();
                    System.out.println("t3 end.");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
